package com.sunda.spmswms.mapper;

import com.sunda.spmscommon.ResponseResult;
import com.sunda.spmswms.entity.WithdrawTask;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 移动冲销表 Mapper 接口
 * </p>
 *
 * @author Wayne
 * @since 2021-04-25
 */
@Mapper
public interface WithdrawTaskMapper extends BaseMapper<WithdrawTask> {


    @Select("<script>" +
            "SELECT\n" +
            "  WDT.UUID AS \"uuid\",\n" +
            "  WDT.TASK_ID AS \"taskId\",\n" +
            "  WDT.WERKS AS \"werks\",\n" +
            "  WDT.WHS_LOCATION_CODE AS \"whsLocationCode\",\n" +
            "  WDT.CREATE_USERID AS \"createUserId\",\n" +
            "  WDT.CREATE_DATE AS \"createDate\",\n" +
            "  WDT.DELIVERY_NOTE_SAP AS \"deliveryNoteSap\",\n" +
            "  WDT.PDA_SN AS \"pdaSN\",\n" +
            "  WDT.MOBILE_TYPE AS \"mobileType\",\n" +
            "  WDT.TASK_CATEGORY AS \"taskCategory\",\n" +
            "  WDT.RELATED_TASK_ID AS \"relatedTaskId\",\n" +
            "  WDT.SAP_VOUCHER_NUMBER AS \"sapVoucherNumber\"\n" +
            "FROM WITHDRAW_TASK WDT\n" +
            "WHERE 1=1\n" +
            "   <when test='userId != null'> AND WDT.CREATE_USERID = #{userId}</when>\n" +
            "   <when test='deliveryNoteSap != null'> AND WDT.DELIVERY_NOTE_SAP = #{deliveryNoteSap}</when>\n" +
            "   <when test='mobileType != null'> AND WDT.MOBILE_TYPE = #{mobileType}</when>\n" +
            "   <when test='taskCategory != null'> AND WDT.TASK_CATEGORY = #{taskCategory}</when>\n" +
            "   <when test='relatedTaskId != null'> AND WDT.RELATED_TASK_ID = #{relatedTaskId}</when>\n" +
            "</script>")
    List<Map<String, Object>> getWithdrawTasks(@Param("userId") String userId,
                                               @Param("deliveryNoteSap") String deliveryNoteSap,
                                               @Param("mobileType") String mobileType,
                                               @Param("taskCategory") String taskCategory,
                                               @Param("relatedTaskId") String relatedTaskId);

}
